const { contextBridge, ipcRenderer } = require('electron');

let mac = 0;
ipcRenderer.on('mac', (event, value) => {
    mac = value;
})


let is_upload = 0;
ipcRenderer.on('isUpdateNow', (event, value) => {
    is_upload = 1;
})

let progressValue = 0;
ipcRenderer.on('downloadProgress', (event, value) => {
    progressValue = value;
})

let errorInfo = "";
ipcRenderer.on('uploadError', (event, value) => {
    errorInfo = value;
})


contextBridge.exposeInMainWorld('api', {
    counter: () => {
        return mac;
    },
    updated: ()=> {
        return is_upload
    },
    updateProgress: () => {
        return progressValue
    },
    sendMessageToMainProcess: () => {
        ipcRenderer.send('updateNow');
    },
    uploadError: () => {
        return errorInfo
    }
    //   counter: (callback) => {
    //     ipcRenderer.on('mac', (event, value) => {
    //         console.log(value);
    //         callback(value);
    //     })
    //   }
})


